/**
*
* 2007-11-6 下午01:09:03
* @author xuhuan
*/

package edu.ccut.saturn.studio.wfg.part;

import org.eclipse.draw2d.Figure;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.gef.GraphicalEditPart;
import org.eclipse.gef.tools.CellEditorLocator;
import org.eclipse.gef.tools.DirectEditManager;
import org.eclipse.swt.events.VerifyListener;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.widgets.Text;

import edu.ccut.saturn.studio.wfg.model.Shape;

public class NodeDirectEditManager extends DirectEditManager {
	Font scaledFont;

    protected VerifyListener verifyListener;

    protected Figure saturnFigure;
    
	@SuppressWarnings("unchecked")
	public NodeDirectEditManager(GraphicalEditPart source, Class editorType,
			CellEditorLocator locator) {
		super(source, editorType, locator);
        this.saturnFigure = (Figure) source.getFigure();
	}

	@Override
	protected void initCellEditor() {

        Text text = (Text) getCellEditor().getControl();
        getCellEditor().setValue(((Shape) getEditPart().getModel()).getName());
        IFigure figure = ((GraphicalEditPart) getEditPart()).getFigure();
        scaledFont = figure.getFont();
        FontData data = scaledFont.getFontData()[0];
        Dimension fontSize = new Dimension(0, data.getHeight());
        saturnFigure.translateToAbsolute(fontSize);
        data.setHeight(fontSize.height);
        scaledFont = new Font(null, data);
        text.setFont(scaledFont);
        text.selectAll();
	}
}
